{echo:JS::import('dialog?skin=tinysimple');}
{echo:JS::import('dialogtools');}
{set:$config = Config::getInstance(); $other = $config->get('other'); $reg_way = isset($other['other_reg_way'])?$other['other_reg_way']:0;$reg_way = explode(',',$reg_way);$reg_way = array_flip($reg_way);}
<div class="magic-bg right" >
    <div class="simple-box "  style="width:530px;height:540px;left:100px">
        <div class="title">
        <div class="sub-1"><h1>用户注册</h1></div><div class="sub-2"><a href="{url:/simple/login}">会员登录</a></div>
        </div>
        <form action="{url:/simple/reg_act}" class="reg-box" method="post" callback="checkReadme">

            <input type="hidden" name="redirectURL" value="{$redirectURL|$this->perPage()}">
            <ul class="form  ">
                
                <li><span class="perfix fa">&#xf007;</span><input name="number" id="number" class="input" pattern="required" placeholder="推荐编号" alt="推荐编号不能为空!">
                </li>
                <li><span class="perfix fa">&#xf007;</span><input name="uname" id="uname"  class="input" pattern="mobi" placeholder="手机号" alt="手机号码格式不正确!">
                &nbsp;<input type="button" id="btn_get_validate" value="获取短信验证码" style="cursor:pointer;color:#fff;background-color:#dd2727;border-color:#c71f1f;height:40px;" onclick="get_validate_code()"/>
                </li>

                <li>
                	<span class="perfix fa">&#xf023;</span>
                	<input minlen=6 maxlen=20 class="input" type="password" name="password" pattern="required" placeholder="登录密码" alt="6-20任意字符组合">
                </li>
                <li>
                	<span class="perfix fa">&#xf084;</span><input minlen=6 maxlen=20 class="input" type="password"  name="passwordtwo" pattern="required" placeholder="交易密码" alt="6-20任意字符组合">
                </li>
				<li>
					<span class="perfix fa">&#xf02a;</span><input minlen=6 maxlen=6  class="input" type="text"  name="validate_code" id="validate_code" pattern="\d{6}" placeholder="短信验证码" alt="短信验证码为6为数字">
				</li>
                <li>
                    <span class="perfix fa">&#xf02a;</span>
                    <input type="text" class="input-sm" name="verifyCode" id="verifyCode"  pattern="\w{4}" maxlength="4" style="width: 80px;" placeholder='验证码' alt="验证码不正确">
                    <img id="captcha_img"  src="{url:/simple/captcha/h/40/w/120/bc/f1f1f1}">
                    <label><a href="javascript:void(0)" class="red" onclick="document.getElementById('captcha_img').src='{url:/simple/captcha/h/40/w/120/bc/f1f1f1/random/}'+Math.random()">切换</a></label>
                </li>
                <li>
                	<dt>&nbsp;</dt>
                		<dd><input id="readme" type="checkbox" alt="同意后才可注册"><label></label><label>我已阅读并同意《<a id="user-license" href="javascript:;">{$site_title}用户注册协议</a>》</label></dd>
            	</li>
            <li><button class="btn btn-main " style="padding:10px 40px; width:100%;">同意协议，立即注册</button></li>
            {token:key=reg}
            </ul>

    </form>
</div>
    <div class="login-bj fr"></div>

</div>

<div id="license-content" style="display:none;">
    <div style="height:400px;overflow:auto">
    {query:name=help where=id eq 14}
    {$item['content']}
    {/query}
    </div>
    <div class="mt10 tc"><a href="javascript:closeLicense();" class="btn btn-main">同意用户注册协议</a></div>
</div>

{echo:JS::import('form')}
<script type="text/javascript">

    var dlg;
	$("#user-license").on("click",function(){
		dlg = dialog({id:'license-dialog',opacity:0.3,padding:'20px 10px 10px 20px',width:900,title:'用户注册协议',content:document.getElementById('license-content'),lock:true});
        dlg.showModal();
	});

	function closeLicense(){
		$('#readme').attr("checked",'true');
		autoValidate.showMsg({id:document.getElementById('readme'),error:false,msg:''});
		dlg.close().remove();
	}
	
	
	function get_validate_code()
	{
		var mobile = $.trim($("#uname").val());
		if(mobile == '')
		{
			alert('手机号码不能为空');
			return;
		}
		var mobile_pattern = /^1[3-9]\d{9}$/;
		if(!mobile_pattern.test(mobile))
		{
			alert('手机号码不合法');
			return;
		}
		
		$("#btn_get_validate").attr("disabled", true);
		$.post("{url:/simple/sms_send}",{mobile:mobile},function(result){
		      alert(result);
		      $("#btn_get_validate").attr("disabled", false);
		  });
		
		
	}
	

	/*
	$("input[name='uname']").on("change",function(event){
		if(autoValidate.validate(event)){
			$.post("{url:/ajax/uname/uname/}"+$(this).val(),function(data){
			autoValidate.showMsg({id:document.getElementById('uname'),error:!data['status'],msg:data['msg']});
		},'json');
		}
	});
	*/

    $("input[name='t_name']").on("change",function(event){
        if(autoValidate.validate(event)){
            $.post("{url:/ajax/t_name/t_name/}"+$(this).val(),function(data){
            autoValidate.showMsg({id:document.getElementById('t_name'),error:!data['status'],msg:data['msg']});
        },'json');
        }
    });
    $("input[name='jd_name']").on("change",function(event){
        if(autoValidate.validate(event)){
            $.post("{url:/ajax/jd_name/jd_name/}"+$(this).val(),function(data){
            autoValidate.showMsg({id:document.getElementById('jd_name'),error:!data['status'],msg:data['msg']});
        },'json');
        }
    });

    // $("input[name='mobile']").on("change",function(event){
    //     if(autoValidate.validate(event)){
    //         $.post("{url:/ajax/mobile/mobile/}"+$(this).val(),function(data){
    //         autoValidate.showMsg({id:document.getElementById('mobile'),error:!data['status'],msg:data['msg']});
    //     },'json');
    //     }
    // });

	$("input[name='verifyCode']").on("change",function(){
		$.post("{url:/ajax/verifyCode/verifyCode/}"+$(this).val(),function(data){
			autoValidate.showMsg({id:document.getElementById('verifyCode'),error:!data['status'],msg:data['msg']});
		},'json');
	})
	$("#readme").on("change",function(){
		if($("#readme:checked").length>0)autoValidate.showMsg({id:document.getElementById('readme'),error:false,msg:''});
		else autoValidate.showMsg({id:document.getElementById('readme'),error:true,msg:'同意后才可注册'});
	});
	function checkReadme(e){
		if(e) return false;
		else{
			if($("#readme:checked").length>0)return true;
			{
				autoValidate.showMsg({id:document.getElementById('readme'),error:true,msg:'同意后才可注册'});
				return false;
			}
		}
	}
	{if:isset($invalid)}
		var form = new Form();
		form.setValue('email', '{$email}');
		autoValidate.showMsg({id:$("input[name='{$invalid['field']}']").get(0),error:true,msg:"{$invalid['msg']}"});
	{/if}

    $("input[pattern]").on("blur",function(event){
            $(".invalid-msg , .valid-msg").hide();
            var current_input = $(this);
            var result = autoValidate.validate(event);
            if(result){
                    current_input.parent().removeClass('invalid').addClass('valid');
                }else{
                    current_input.parent().removeClass('valid').addClass('invalid');
                }
            if(result){
                if(current_input.attr('id')=='email'){
                    $.post("{url:/ajax/email/email/}"+$(this).val(),function(data){
                        var msg = '合法用户';
                        if(!data['status']){
                            msg = '用户已存在';
                            current_input.next().show();
                            current_input.parent().removeClass('valid').addClass('invalid');
                        }else{
                            current_input.parent().removeClass('invalid').addClass('valid');
                        }
                        autoValidate.showMsg({id:document.getElementById('email'),error:!data['status'],msg:msg});
                    },'json');
                }if(current_input.attr('id')=='mobile'){
                    $.post("{url:/ajax/mobile/mobile/}"+$(this).val(),function(data){
                        var msg = '合法用户';
                        if(!data['status']){
                            msg = '用户已存在';
                            current_input.next().show();
                            current_input.parent().removeClass('valid').addClass('invalid');
                        }else{
                            current_input.parent().removeClass('invalid').addClass('valid');
                        }
                        autoValidate.showMsg({id:document.getElementById('mobile'),error:!data['status'],msg:msg});
                    },'json');
                }else if(current_input.attr('id')=='verifyCode'){
                    $.post("{url:/ajax/verifyCode/verifyCode/}"+$(this).val(),function(data){
                        autoValidate.showMsg({id:document.getElementById('verifyCode'),error:!data['status'],msg:data['msg']});
                        if(!data['status']) current_input.next().show();
                    },'json');
                }
                $(".invalid-msg").show();
            }else{
                current_input.next().show();
            }
        });
</script>
